package com.jh.pattern.prototype.simpleclone;

import java.util.ArrayList;
import java.util.List;

/**
 * @author JH_Wong
 * @projectName newforward
 * @title
 * @package com.jh.pattern.prototype.simpleclone
 * @description
 * @date 2019-05-30 14:12
 */
public class ConcreatePrototype implements Prototype{

    private Integer age;
    private String name;
    private List hobbies;

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public List getHobbies() {
        return hobbies;
    }

    public void setHobbies(List hobbies) {
        this.hobbies = hobbies;
    }

    @Override
    public Prototype clone() {
        ConcreatePrototype tmp = new ConcreatePrototype();
        tmp.setAge(this.age);
        tmp.setName(this.name);
        tmp.setHobbies(this.hobbies);
        return tmp;
    }

    public static void main(String[] args) {
        ConcreatePrototype a = new ConcreatePrototype();
        a.setAge(new Integer(222));
        a.setName(new String("333"));
        List<String> list = new ArrayList<>();
        list.add("a");
        a.setHobbies(list);

        ConcreatePrototype b = (ConcreatePrototype) a.clone();

        System.out.println("age：");
        System.out.println(a.getAge().hashCode());
        System.out.println(b.getAge().hashCode());

        System.out.println("name：");
        System.out.println(a.getName().hashCode());
        System.out.println(b.getName().hashCode());

        System.out.println("list：");
        System.out.println(a.getHobbies() == b.getHobbies());
    }
}
